package com.rober.algorithm;

import java.util.Arrays;
/**
 * @FOR 二分法查找 111
 * @author roberluo
 */
public class BinarySearch {
	public static void main(String[] args) {
        int[] arr = {7,8,9,10,1,2,3};
        Arrays.sort(arr);
        int templow = 0;
        int tempHeight = arr.length - 1 ;
        int searchWorld  = 10;
        int i= 0;
        int middle = 0;
        while(templow <= tempHeight) {
        	 middle = (templow + tempHeight)/2;
        	if(searchWorld == arr[middle]) {
        		break;
        	};
        	if(searchWorld > arr[middle]) {
        		templow =middle+1;
        	};
        	if(searchWorld < arr[middle]) {
        		tempHeight =middle-1;
        	};
        	System.out.println("循环次数："+i++);
        }
        System.out.println(Arrays.toString(arr));
        System.out.println("索引:"+middle);
	}

	
}
